<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body style="padding:10px;">
<p>说明：
    <span>方法体内的代码行数建议不超过120行? 超过建议召开会议</span>
</p>
<br/>
<p>正例：</p>
<div style="margin:10px;padding:10px;border:1px solid #000000;white-space: pre-line;">
    /**
    * 保存考试记录信息
    * 1. 参数验证
    * 2. 根据试卷ID查询普通试卷或随机试卷
    * 3. 设置考试人员考试记录基础信息
    * 4. 设置培训（其他）考试记录基础信息
    * 5. 试卷类型是普通试卷，获取考试记录题目数据
    * 6. 编辑考试记录需查询原培训（其他）考试记录
    * 7. 通过上下文获取服务对象以便实现事务控制
    * 8. 保存业务数据
    * @param record
    * @return com.dongbao.core.tips.Tip
    * @author wangzhidong
    * @date 2021/5/10 16:42
    **/
    @Override
    public Tip toSave(RecExamTrainOtherRecord record) {
        //1. 参数验证
        Tip tip = this.toSaveParameterVerification(record);
        if (!tip.isSuccess()) {
            return tip;
        }

        //2. 根据试卷ID查询普通试卷或随机试卷
        RecGeneralOrRandomExamPaperVO paperVO = this.getGeneralOrRandomExamPaperByExamPaperId(record.getRecExamPaperId());
        if (ToolUtil.isEmpty(paperVO)) {
            //考试试卷不存在或不是已启用状态，请查看
            return tip.error(201, ToolUtil.getLocaleValue(&quot;rec_exam_train_other_record&quot;, &quot;exam_paper_error&quot;));
        }

        //3. 设置考试人员考试记录基础信息
        List&lt;RecExamTrainOtherRecordEmp&gt; recordEmpList = this.setRecExamTrainOtherRecordEmpData(record);
        if (ToolUtil.isEmpty(recordEmpList)) {
            //考生人员范围无数据，请重新选择！
            return tip.error(201, ToolUtil.getLocaleValue(&quot;rec_exam_train_other_record&quot;, &quot;no_data_for_range&quot;));
        }

        //4. 设置培训（其他）考试记录基础信息
        record = this.setRecExamTrainOtherRecordData(record, recordEmpList, paperVO);

        //5. 试卷类型是普通试卷，获取考试记录题目数据
        RecExamQuestionAndOptionVO questionAndOptionVO = null;
        if (RecConstants.ExamType.GENERAL.equals(record.getExamType())) {
            questionAndOptionVO = this.getRecExamRecordQuestionAndOptionData(record.getRecExamPaperId(), record.getId());
        }

        //6. 编辑考试记录需查询原培训（其他）考试记录
        RecExamTrainOtherRecord oldRecord = null;
        if (!record.getIsNew().equals(Const.DEFAULT_YES_STR)) {
            oldRecord = recExamTrainOtherRecordDao.getById(record.getId());
            if (ToolUtil.isEmpty(oldRecord)) {
                //考试记录不存在，请刷新页面重试！
                throw new BusinessException(ToolUtil.getLocaleValue(&quot;rec_exam_train_other_record&quot;, &quot;exam_record_does_not_exist&quot;));
            }
        }

        //7. 通过上下文重新获取service对象以便实现事务控制（事务在本service方法中具有传递性，在方法开始前如果未加事务，且未调用其他服务类事务方法执行，调用本Service其他事务方法是不会走事务的）
        IRecExamTrainOtherRecordService recordService =
        SpringContextUtil.getBean(IRecExamTrainOtherRecordService.class);

        //8. 保存业务数据
        recordService.toSaveBusinessData(record, oldRecord, recordEmpList, questionAndOptionVO);

        return new SuccessTip();
    }

</div>
<br/>
<p>反例：</p>
<div style="margin:10px;padding:10px;border:1px solid #000000;white-space: pre-line;">
<br/>    // 这代码写的太长，超过80行，像天书一样，不符合单一职责
<br/>    @Override
<br/>    @Transactional
<br/>    public Tip generateSiteEvaluateRecord(RecTrainRecordAddVO recTrainRecordAddVO) {
<br/>    Tip result = new SuccessTip();
<br/>
<br/>    if (ObjectUtil.isEmpty(recTrainRecordAddVO)) {
<br/>    result.error(1, &quot;参数不能为空！&quot;);
<br/>    return result;
<br/>    }
<br/>
<br/>    final Long recEvaluationTempletId = recTrainRecordAddVO.getRecEvaluationTempletId();
<br/>
<br/>
<br/>    if (ToolUtil.isEmpty(recEvaluationTempletId)) {
<br/>    result.error(1, &quot;模板id不能为空！&quot;);
<br/>    return result;
<br/>    }
<br/>
<br/>    List&lt;Long&gt; empIds = recTrainRecordAddVO.getEmpIds();
<br/>
<br/>    if (ToolUtil.isEmpty(empIds)) {
<br/>    result.error(1, &quot;评估人信息不能为空！&quot;);
<br/>    return result;
<br/>    }
<br/>    final RecEvaluationTemplet recEvaluationTemplet = recEvaluationTempletService.getById(recEvaluationTempletId);
<br/>
<br/>
<br/>    final Long templetId = recEvaluationTemplet.getId();
<br/>    log.info(&quot;----------templetId：&quot; + templetId);
<br/>
<br/>    final List&lt;RecEvaluationTempletQuestion&gt; templateQuestions =
<br/>    recEvaluationTempletQuestionService.list(new CommonQueryWrapper&lt;RecEvaluationTempletQuestion&gt;().eq(
<br/>    &quot;rec_evaluation_templet_id&quot;, templetId));
<br/>    List&lt;RecTrainEvaluationRecordQuestion&gt; addQuestionList = new ArrayList&lt;RecTrainEvaluationRecordQuestion&gt;();
<br/>    List&lt;RecTrainEvaluationRecordOptions&gt; addOptionList = new ArrayList&lt;RecTrainEvaluationRecordOptions&gt;();
<br/>    RecTrainEvaluationRecord recTrainEvaluationRecord = new RecTrainEvaluationRecord();
<br/>    BeanUtils.copyProperties(recTrainRecordAddVO, recTrainEvaluationRecord);
<br/>
<br/>    long recTrainEvaluationRecordId = IdWorker.getId();
<br/>    recTrainEvaluationRecord.setId(recTrainEvaluationRecordId);
<br/>    recTrainEvaluationRecord.setHeaderUrl(recEvaluationTemplet.getHeaderUrl());
<br/>    recTrainEvaluationRecord.setEvaluationNum(empIds.size());
<br/>    recTrainEvaluationRecord.setEvaluationStatus(EvaluationStatusType.TO_EVALUATE.getValue());
<br/>    recTrainEvaluationRecord.setCode(seqService.getCodeBySeq(&quot;rec_train_evaluation_code&quot;));
<br/>    recTrainEvaluationRecord.setIsNotice(Const.DEFAULT_NO_STR);
<br/>    if (!ToolUtil.isEmpty(templateQuestions)) {
<br/>    for (RecEvaluationTempletQuestion question : templateQuestions) {
<br/>    Long questionId = question.getId();
<br/>    RecTrainEvaluationRecordQuestion addQuestion = new RecTrainEvaluationRecordQuestion();
<br/>    BeanUtils.copyProperties(question, addQuestion);
<br/>    addQuestion.setMaxScore(question.getScore());
<br/>    //未开始评估时没有得分
<br/>    addQuestion.setScore(null);
<br/>    long parentId = ToolUtil.isEmpty(question.getParentId()) ? 0 : question.getParentId();
<br/>    long id = IdWorker.getId();
<br/>
<br/>    if (parentId == 0) {
<br/>    addQuestion.setRecTrainEvaluationRecordId(recTrainEvaluationRecordId);
<br/>    addQuestion.setId(id);
<br/>    ToolUtil.setCreateAndOrgInfo(addQuestion);
<br/>    getOpts(templetId, addOptionList, recTrainEvaluationRecordId, questionId, id);
<br/>    addQuestionList.add(addQuestion);
<br/>
<br/>    final List&lt;RecEvaluationTempletQuestion&gt; sonQuestions =
<br/>    recEvaluationTempletQuestionService.list(new CommonQueryWrapper&lt;RecEvaluationTempletQuestion&gt;                                                               ().eq(&quot;parent_id&quot;, questionId));
<br/>    if (!CollectionUtils.isEmpty(sonQuestions)) {
<br/>    sonQuestions.stream().forEach(son -&gt; {
<br/>    RecTrainEvaluationRecordQuestion sonAddQuestion = new RecTrainEvaluationRecordQuestion();
<br/>    BeanUtils.copyProperties(son, sonAddQuestion);
<br/>    sonAddQuestion.setMaxScore(son.getScore());
<br/>    long sonId = IdWorker.getId();
<br/>    sonAddQuestion.setId(sonId);
<br/>    sonAddQuestion.setParentId(id);
<br/>    sonAddQuestion.setRecTrainEvaluationRecordId(recTrainEvaluationRecordId);
<br/>    ToolUtil.setCreateAndOrgInfo(sonAddQuestion);
<br/>    getOpts(templetId, addOptionList, recTrainEvaluationRecordId, son.getId(), son.getId());
<br/>    addQuestionList.add(sonAddQuestion);
<br/>    });
<br/>    }
<br/>    }
<br/>    }
<br/>    }
<br/>
<br/>    log.info(&quot;recTrainEvaluationRecord{}&quot; + recTrainEvaluationRecord.toString());
<br/>
<br/>    ToolUtil.setCreateAndOrgInfo(recTrainEvaluationRecord);
<br/>    recTrainEvaluationRecord.setQuestionNum(recEvaluationTemplet.getQuestionNum());
<br/>    recTrainEvaluationRecordService.insert(recTrainEvaluationRecord);
<br/>    recTrainEvaluationRecordQuestionService.insertBatch(addQuestionList);
<br/>
<br/>    if (!CollectionUtils.isEmpty(addOptionList)) {
<br/>    recTrainEvaluationRecordOptionsService.insertBatch(addOptionList);
<br/>    }
<br/>
<br/>    //保存每个评估人的问卷信息
<br/>    List&lt;RecTrainEvaluationEmpRecord&gt; empRecordList = new ArrayList&lt;RecTrainEvaluationEmpRecord&gt;();
<br/>    empIds.forEach(empId -&gt; {
<br/>    EmpInfo empInfo = empInfoService.getEmpByOriginId(empId);
<br/>    RecTrainEvaluationEmpRecord empRecord = new RecTrainEvaluationEmpRecord();
<br/>    long id = IdWorker.getId();
<br/>    empRecord.setId(id);
<br/>    empRecord.setEmpOriginId(empId);
<br/>    empRecord.setDomainEmpOriginId(recTrainRecordAddVO.getDomainEmpOriginId());
<br/>    empRecord.setEmpOriginName(empInfo.getName());
<br/>    empRecord.setDomainName(recTrainRecordAddVO.getDomainName());
<br/>    empRecord.setDomainType(recTrainRecordAddVO.getDomainType());
<br/>    empRecord.setEvaScare(0);
<br/>    empRecord.setRecTalentEvaluationRecordId(recTrainEvaluationRecordId);
<br/>    empRecord.setEvaluationStatus(EvaluationStatusType.TO_EVALUATE.getValue());
<br/>    empRecord.setCode(seqService.getCodeBySeq(&quot;rec_train_evaluation_emp_code&quot;));
<br/>    empRecord.setTrainEvaluationRecordName(recEvaluationTemplet.getName());
<br/>    ToolUtil.setCreateAndOrgInfo(empRecord);
<br/>
<br/>    empRecordList.add(empRecord);
<br/>
<br/>    });
<br/>
<br/>    log.info(&quot;保存培训人员记录个数{}&quot; + empRecordList.size());
<br/>    if (!CollectionUtils.isEmpty(empRecordList)) {
<br/>    recTrainEvaluationEmpRecordService.insertBatch(empRecordList);
<br/>    }
<br/>
<br/>    //发送协同消息
<br/>    //        String title = &quot;1&quot;.equals(recTrainEvaluationRecord.getDomainType()) ?
<br/>    //                &quot;课程评估&quot; : &quot;2&quot;.equals(recTrainEvaluationRecord.getDomainType()) ?
<br/>    //                    &quot;讲师评估&quot; : &quot;站别认证评估&quot;;
<br/>    if (&quot;3&quot;.equals(recTrainRecordAddVO.getType())) {
<br/>    result.setRows(recTrainEvaluationRecordId);
<br/>    return result;
<br/>    }
<br/>    List&lt;RecCoporationMsg&gt; recCoporationMsgs = new ArrayList&lt;&gt;();
<br/>    for (RecTrainEvaluationEmpRecord empRecord : empRecordList) {
<br/>    StringBuilder title = new StringBuilder();
<br/>    if (ToolUtil.isEmpty(recTrainRecordAddVO.getType())) {
<br/>    //可能存在ltg新加站别认证评估代码未更新，标题使用之前标题
<br/>    title.append(&quot;站别认证评估&quot;);
<br/>    } else {
<br/>    EmpInfo empInfo = empInfoService.getEmpByOriginId(empRecord.getDomainEmpOriginId());
<br/>    title.append(empInfo.getEmpNo()).append(empInfo.getName());
<br/>    //实操打分标题
<br/>    if (&quot;1&quot;.equals(recTrainRecordAddVO.getType())) {
<br/>    title.append(&quot;的站别实操考试评估&quot;);
<br/>    } else if (&quot;2&quot;.equals(recTrainRecordAddVO.getType())) {//认证后评估标题
<br/>    title.append(&quot;的站别认证评估&quot;);
<br/>    }
<br/>    }
<br/>
<br/>    RecCoporationMsg recCoporationMsg = new RecCoporationMsg();
<br/>    recCoporationMsg.setStatus(Const.DEFAULT_NO);
<br/>    recCoporationMsg.setType(1);
<br/>    recCoporationMsg.setId(IdWorker.getId());
<br/>    recCoporationMsg.setLeaderId(empRecord.getEmpOriginId());
<br/>    recCoporationMsg.setEmpOriginId(empRecord.getEmpOriginId());
<br/>    recCoporationMsg.setTitle(title.toString());
<br/>    if (!ToolUtil.isEmpty(recTrainEvaluationRecord.getEndTime())) {
<br/>    recCoporationMsg.setEndDate(DateUtil.LocalDateTimeToUdate(recTrainEvaluationRecord.getEndTime()));
<br/>    }
<br/>    recCoporationMsg.setStartDate(DateUtil.LocalDateTimeToUdate(recTrainEvaluationRecord.getStartTime()));
<br/>    recCoporationMsg.setInfoId(empRecord.getId());
<br/>    recCoporationMsg.setUrl(&quot;/recTrainEvaluationRecord/recTrainEvaluationExam?id=&quot; +
<br/>    recTrainEvaluationRecord.getId() + &quot;&amp;assessmentType=recTrainEvaluationRecord&amp;from=selfDeal&quot;);
<br/>    ToolUtil.setCreateInfo(recCoporationMsg);
<br/>    recCoporationMsgs.add(recCoporationMsg);
<br/>    //            final boolean b = recCoporationMsgService.saveRecCoporationMsg(recCoporationMsg);
<br/>    }
<br/>
<br/>    if (!CollectionUtils.isEmpty(recCoporationMsgs)) {
<br/>    recCoporationMsgService.insertOrUpdateBatch(recCoporationMsgs);
<br/>    }
<br/>    result.setRows(recTrainEvaluationRecordId);
<br/>    return result;
<br/>    }
<br/>
</div>
</body>
</html>